//---------------------------------------------------------------------
// ianimeEx.js (default extension for ianime.js)
//   version 0.26 (Dec. 3rd, 2007)
// Copyright (c) 2007-2008 Satoshi Nakajima
//
// See ianime.js regarding the MIT License
//---------------------------------------------------------------------

iAnime.effects.fadeout = function(element, t, x, y) {
    iAnime.drawElement(element, t, x, y);
    iBrowse.setOpacity(element, 1-t);
};

iAnime.effects.fadein = function(element, t, x, y) {
    iAnime.drawElement(element, t, x, y);
    iBrowse.setOpacity(element, t);
};

iAnime.effects.show = function(element, t, x, y) {
    iAnime.drawElement(element, t, x, y);
    element.style.visibility = 'visible';
};

iAnime.effects.hide = function(element, t, x, y) {
    element.style.visibility = 'hidden';
    iAnime.drawElement(element, t, x, y);
};

iAnime.effects.blink = function(element, t, x, y) {
    iAnime.drawElement(element, t, x, y);
    var index = Math.floor(t * ((this.repeat-1)*2+1)) % 2;
    element.style.visibility = iAnime.effects.blink.visibility[index];
};

iAnime.effects.blink.visibility = ['hidden', 'visible'];

iAnime.effects.bounce = function(e,t,x,y) {
    e.style.left = x + "px";
    e.style.top = y + "px";
};

iAnime.effects.bounce.ratio = function(t) {
    if (t<0.66)
        return (t*t/0.66/0.66);
    var r0;
    if (t<0.88)
        r0 = 2*(0.11-(t-0.77)*(t-0.77)/0.11);
    else if (t<0.96)
        r0 = (0.04-(t-0.92)*(t-0.92)/0.04);
    else
        r0 = (0.02-(t-0.98)*(t-0.98)/0.02);
    return 1-r0;
};

iAnime.effects.easein = function(e,t,x,y) {
    e.style.left = x + "px";
    e.style.top = y + "px";
};

iAnime.effects.easein.ratio = function(t) {
    return t*t;
};

iAnime.effects.easeout = function(e,t,x,y) {
    e.style.left = x + "px";
    e.style.top = y + "px";
};

iAnime.effects.easeout.ratio = function(t) {
    return 1-(1-t)*(1-t);
};

iAnime.effects.easeinout = function(e,t,x,y) {
    e.style.left = x + "px";
    e.style.top = y + "px";
};

iAnime.effects.easeinout.ratio = function(t) {
    if (t<0.5)
        return t*t/0.5;
    return 1-(1-t)*(1-t)/0.5;
};

iAnime.effects.elastic = function(e,t,x,y) {
    e.style.left = x + "px";
    e.style.top = y + "px";
};

iAnime.effects.elastic.ratio = function(t) {
    return 1-(1-t)*(1-t)*Math.cos(Math.PI*3.5*t);
};

iAnime.effects.jump = function(e,t,x,y) {
    var h = (1-4*(t-0.5)*(t-0.5));
    e.style.left = x + this.j_x * h + "px";
    e.style.top = y + this.j_y * h + "px";
};

iAnime.effects.jump.init = function(item) {
    var dist = Math.sqrt(item._dx*item._dx + item._dy*item._dy);
    item.j_x = -item._dy * item.j_height / dist;
    item.j_y = item._dx * item.j_height / dist;
};

iAnime.effects.jumpbounce = function(e,t,x,y) {
    var r0;
    if (t<0.66)
        h = 1-(t-0.33)*(t-0.33)/0.33/0.33;
    else if (t<0.88)
        h = (1-(t-0.77)*(t-0.77)/0.11/0.11)/2;
    else if (t<0.96)
        h = (1-(t-0.92)*(t-0.92)/0.04/0.04)/4;
    else
        h = (1-(t-0.98)*(t-0.98)/0.02/0.02)/8;
    e.style.left = x + this.j_x * h + "px";
    e.style.top = y + this.j_y * h + "px";
};

iAnime.effects.jumpbounce.init = iAnime.effects.jump.init;

iAnime.effects.settext = function(element, t, x, y) {
    var text = this.text;
    iBrowse.setText(element, text.substr(0, Math.floor(text.length*t)));
    iAnime.drawElement(element, t, x, y);
};

